home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / STRNCPY.C < prev    next >
Text File  |  1993-01-04  |  768b  |  30 lines

  1.  
  2. /*  File   : strncpy.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 20 April 1984
  5.     Defines: strncpy()
  6.  
  7.     strncpy(dst, src, n) copies up to n characters of src  to  dst.   It
  8.     will  pad  dst  on the right with NUL or truncate it as necessary to
  9.     ensure that n characters exactly are transferred.   It  returns  the
  10.     old value of dst as strcpy does.
  11. */
  12.  
  13. #include "strings.h"
  14.  
  15. char *strncpy(dst, src, n)
  16.     register char *dst, *src;
  17.     register int n;
  18.     {
  19.         char *save;
  20.  
  21.         for (save = dst;  --n >= 0; ) {
  22.             if (!(*dst++ = *src++)) {
  23.                 while (--n >= 0) *dst++ = NUL;
  24.                 return save;
  25.             }
  26.         }
  27.         return save;
  28.     }
  29.  
  30.